package gbench.sandbox.record.cph;

import org.junit.jupiter.api.Test;
import gbench.common.tree.LittleTree.IRecord;
import gbench.commonApp.data.DataMatrixApp;
import static gbench.common.tree.LittleTree.Elem.*;
import static gbench.common.tree.LittleTree.IRecord.*;
import static java.util.Arrays.*;

import java.text.MessageFormat;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Stream;

public class JunitElem {
    
    @Test
    public void foo() {
        final var digits = "0123456789".split(""); 
        final var mx = cph2(asList(digits,digits,digits,digits,digits))
        .map(IRecord::L2REC)
        .collect(DataMatrixApp.imc);
        System.out.println(mx);
    }
    
    @Test
    public void bar() {
        final var digits = "0123456789".split(""); 
        final var ai = new AtomicInteger(0);
        cph2(asList(digits,digits,digits,digits,digits,digits))
        .parallel()
        .forEach(rec->{
            final var n = ai.incrementAndGet();
            System.out.println(MessageFormat.format("{0} #  {1}", n,rec));
        });
    }
    
    @Test
    public void qux() {
        final var digits = "0123456789".split(""); 
        final var ai = new AtomicInteger(0);
        cph2(digits,digits,digits,digits,digits,digits)
        .forEach(rec->{
            final var n = ai.incrementAndGet();
            System.out.println(MessageFormat.format("{0} #  {1}", n,rec));
        });
    }
    
    @SuppressWarnings("unchecked")
    @Test
    public void qux2() {
        final var digits = "0123456789".split(""); 
        cph2(REC("a",digits,"b",digits)
        .filter(p->p.value().getClass().isArray())
        .reduce(p->(Stream<String[]>)(Object) Stream.of(p._2()),Stream.of(),Stream::concat))
        .forEach(System.out::println);
    }
    
}
